const router = require('express').Router()
const db = require('../db.config')

// router.get('/deletestudent', (req, res) => {
//     let { id } = req.query
//     console.log(req.query);
//     console.log(id);
//     let sql = `delete from students where id=${id}`
//     db.query(sql, (err, data) => {
//         res.send({
//             code: 200,
//             success: "删除成功"
//         })
//     })
// })

router.post('/deletestudent', (req, res) => {
    let { ids } = req.query;
    console.log(ids);
    let sql = `delete from students where id IN (${ids.join()})`;
    db.query(sql, (err, data) => {
        if (err) {
            res.status(500).send({
                code: 500,
                error: "删除失败"
            });
        } else {
            res.send({
                code: 200,
                success: "删除成功"
            });
        }
    });
});

module.exports = router

